//
//  SetupController.m
//  EasyToTesco2.0
//
//  Created by 杨森 on 16/6/21.
//  Copyright © 2016年 EasyToTesco. All rights reserved.
//

#import "SetupController.h"
#import "DefaultButton.h"
#import "regardingController.h"


@interface SetupController ()

@end

@implementation SetupController

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:YES];
}

- (void)viewDidLoad {
    [super viewDidLoad];

    self.title = @"设置";
    self.tableView.backgroundColor = BACKGROUND_COLOR;
}

#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 0) {
        return 1;
    }else{
        return 2;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *identifier = @"SetupControllerCell";
    
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:identifier];
    
    if (cell==nil) {
        cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.textLabel.font = FONT(14);
    }
    
    NSArray *setArr = @[@"关于亿乐购物吧",@"清除缓存",@"评价我们"];
 
    if (indexPath.section == 0) {
        cell.textLabel.text = [NSString stringWithFormat:@"%@",setArr[indexPath.row]];

    }else{
       
        cell.textLabel.text = [NSString stringWithFormat:@"%@",setArr[indexPath.row+1]];
    }
    
    
    return cell;
}


#pragma mark >>>>>>>>>>>代理

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        //关于亿乐
        regardingController *regardingVC = [[regardingController alloc] init];
        [self.navigationController pushForm:self.navigationController pushToAndHidden:regardingVC];
    }else if (indexPath.row == 1 && indexPath.section == 1){
        
        //跳转评论
        NSURL * url = [NSURL URLWithString:@"itms-apps://itunes.apple.com/cn/app/yi-le-gou-wu-ba/id1107627163?mt=8"];
        if ([[UIApplication sharedApplication] canOpenURL:url])
        {
            [[UIApplication sharedApplication] openURL:url];
        }
        else
        {
            NSLog(@"can not open");
        }
   
    }else{
        
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 10;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{

    if (section == 0) {
        return 0.01;
    }else{
        return HEIGHT/6;
    }
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    if (section == 0) {
        return nil;
    }else{
        return [self leaveView];
    }
}

- (UIView *)leaveView
{
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0,0,WIDTH, HEIGHT/6)];
    DefaultButton *button = [[DefaultButton alloc] init];
    [button setTitle:@"退出当前账户" forState:UIControlStateNormal];
    [view addSubview:button];
    [button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(view.mas_centerX);
        make.centerY.equalTo(view.mas_centerY);
        make.height.mas_equalTo(view.Height/3);
        make.width.mas_equalTo(WIDTH-30);
    }];
    return view;
}
@end
